<?php
class IndexController extends Zend_Controller_Action
{
	static function initAdmin(&$p_objController)
	{
		$AppUI = Zend_Registry::get('AppUI');
		if (!$AppUI->admin_id || $AppUI->admin_id==-1)
		{
			$p_objController->_redirect(HOST_OPS .'/login');
		}
		
		$intMenuType	= $AppUI->_get(MENU_KEY);
		$intMenuType	= (intval($intMenuType)>0) ? $intMenuType : MENU_SYSTEM;
		
		$p_objController->view->controllerName 	= $p_objController->_request->getParam('controller');
		$p_objController->view->actionName 		= $p_objController->_request->getParam('action');
		$p_objController->view->pageRootUrl 	= HOST_ADMIN.'/'.$p_objController->view->controllerName;
		$p_objController->view->intMenuType		= $intMenuType;
		
		$p_objController->AppUI	= $AppUI;
	}
	
	public function indexAction()
	{	
		$AppUI			= Zend_Registry::get('AppUI');		
		$strCountry		= $this->_request->getParam('country','');		
		if($AppUI->admin_id !=NULL && $AppUI->admin_group_id !=NULL && $strCountry != $AppUI->country
			&& ($AppUI->admin_group_id !=GROUP_Administrator || $AppUI->admin_group_id !=GROUP_Buying 
					|| $AppUI->admin_group_id !=GROUP_Inventory || $AppUI->admin_group_id !=GROUP_Marketing)	
		)
		{
			Common_FCommon::redirect(HOST_OPS .'/login?country=' . $strCountry);
			exit;
		}
		self::dashBoardAction();
		$arrLog = QLogSystem::getGenerateForecastsLog($this->AppUI->country);
		if($arrLog)
		{
			$this->view->arrSystemLog = $arrLog[0];
		}
	}
	
	public function changeMenuAction()
	{
		$intMenuType = $this->_request->getParam('t');
		
		$AppUI	= Zend_Registry::get('AppUI');
		$AppUI->_add(MENU_KEY, $intMenuType);
		#$AppUI->save();
		
		header('Location:'.HOST_ADMIN);
		exit;
	}
	
	public function dashBoardAction()
	{
		self::initAdmin($this);		
		$objForecast		= new QBForecast($this->AppUI->country);
		$arrData = $objForecast->dashBoardForecast();
		
		$this->view->arrData = $arrData;
	}
}
?>
